<style>
  .layui-btn{
    padding: 0 7px !important;
  }
  .layui-laypage a, .layui-laypage span{
    background-color: #f2f2f2;
  }
</style>

<script src="/js/layui/layui.all.js"></script>
<script src="/admin/js/token.js"></script>
<script type="text/html" id="caozuo">
  <input type="submit"  value="编辑" class="layui-btn " lay-submit="" lay-event="updateTheme"/>
</script>

<div class="layui-form-item layui-col-xs12 site-demo-button" id="layerDemo" style="margin-left: 2%;">
  <button type="submit" class="layui-btn " lay-submit="" lay-filter="addTheme" data-method="setTop">
    <span class="glyphicon glyphicon-plus"></span >新增主题</button>
</div>



<script type="text/html" id="tol">
  <div>
    <div style="float:left;">主题管理</div>
    <div style="float:right;margin-right: 50px">共有数据：<span id="count"></span>条</div>
  </div>

</script>
<div class="layui-form">

  <table class="layui-table" id="themedata" lay-filter="themedata"></table>

  <div id="demo7" style="text-align: center"></div>
</div>

<!--</div>-->
<script>

  var pages= localStorage.getItem('page');

  var local_store = layui.data("local_store");
  var local = local_store.token;
  $.ajax({
    type:"get",
    url:"/admin/station/query/stationLoginQuanxXian?stationId="+json.id,
    dataType: "json",
    contentType:"application/json;charset=utf-8",
    // beforeSend: function(request) {
    //   request.setRequestHeader("token", local);
    // },
    success:function (res) {
      if (res.code == 500) {
        alert("权限不足")
        location = "../../admin/main.html";
        return
      }
      }}
    )
  layui.use(['form', 'layedit', 'laydate','table'], function(){
    var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;
    var table = layui.table;

    table.render({
      elem: "#themedata",
      url: "/admin/theme/query/themeAll?station_id="+json.id,
      id: "t",
      // type:'get',
      toolbar:"#tol",
      cols: [[{
        title: "主题编号",
        field: "theme_id",
        width: "17%",
        align: "center"
      },
        {
          title: "主题名称",
          field: "theme_name",
          width: "17%",
          align: "center"
        }
        ,   {
          title: "主题图片",
          field: "theme_image",
          width: "17%",
          align: "center",
          templet: function(d) {
            return "<img width='50px' height='50px' src='" + IMAGE_SERVER +"/" + d.theme_image + "'></img>";
          }
        }
        ,
        {
          title: "主题状态",
          field: "theme_status",
          width: "17%",
          align: "center"
        },
        {
          title: "操作",
          width: "31%",
          align: "center",
          toolbar: "#caozuo"
        }
      //  马爷的那个token。js 修改
      ]],page:{
        curr:pages
      },
      done: function(res, curr, count){
        localStorage.setItem('page',curr);
        $("#count").html(count);
      }
    })

    table.on("tool(themedata)", function (obj) {
      var getdata = obj.data; //获得当前行数据
      var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
      var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）

      switch (layEvent) {
        case "updateTheme":
          // alert("ll")
                console.log(getdata)
            localStorage.setItem("themeId",getdata.theme_id);
            localStorage.setItem("themeName",getdata.theme_name);
            localStorage.setItem("themeImage",getdata.theme_image);
            localStorage.setItem("themeStatus",getdata.theme_status);
            location="#/layui/themeEdit";
          break;
      }
    });

    form.on('submit(addTheme)',function () {

        location="#/layui/addtheme";
        location.reload();
    })
  });

  function GetRequest() {
    var url = decodeURI(location.search); //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
      var str = url.substr(1);
      strs = str.split("&");
      for(var i = 0; i < strs.length; i ++) {
        theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
      }
    }
    return theRequest;
  }

  var json=GetRequest();

</script>

<!--分页-->
<script>
    var laypage = layui.laypage
            ,layer = layui.layer;

</script>

